Repository navigation
Integrate upstream CPU fixes (strided half-precision GEMM, cummax/cummin NaN) - #65
Merged
Merged
Conversation
ml-explore#4947) Co-authored-by: Yunt1 <Yunt1@users.noreply.github.com> Co-authored-by: Cheng <git@zcbenz.com> Ported: osaurus-ai/mlx PR 26 already passes lda and ldb to simd_gemm (the fix for ml-explore/mlx issue 4739). This commit adds what PR 26 did not: ldc for the output, and the BNNS dimensions. The Highway path (simd_low_precision_gemm.h) passes ldc to its simd_gemm call too. tests/blas_tests.cpp keeps PR 26's test and adds Apple's. (cherry picked from commit c3ff43b)
…ml-explore#4912) (cherry picked from commit 5598dfa)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Branch
apple/r4-cpu, 2 commits onorigin/main23f364e (tip 6d29e52).Two CPU fixes that reached ml-explore/mlx main on 2026-11-24, after round 3 was cut. The code is Apple's and its
contributors': each commit is a
git cherry-pick -xof the upstream commit, with the upstream author kept and the(cherry picked from commit …)line recording provenance.segmented_mmin bf16/fp16 gave wrong values (ml-explore/mlx issue 4739). This fork's #26 already passedldaandldbtosimd_gemm. ml-explore#4947 also writes the output with its row strideldc, insimd_gemmand in the BNNS output descriptor. Adds a C++ test.cummaxandcumminon float16 and bfloat16 turned NaN into 0:std::numeric_limitshas no specialization for those types, soquiet_NaN()returned 0. NaN is now built fromfloatand cast. Extendstest_cummax_cummin_nanto float16 and bfloat16.Conflict resolutions
mlx/backend/cpu/gemms/simd_gemm.h,simd_bf16.cpp,simd_fp16.cpp: the fork's files (Pass lda and ldb through to the bf16 and fp16 CPU matmuls #26:ldaandldb; the Highway branch ofsimd_bf16.cppandsimd_fp16.cpp) with Apple'sldcadded.simd_gemm.hnowequals Apple's but for the fork's comment on the strides.
simd_low_precision_gemm.h(the Highway path) now passesldcto its own
simd_gemmcall too.bnns.cpp(the outputstride) applied cleanly.
tests/blas_tests.cpp: both tests stay, Pass lda and ldb through to the bf16 and fp16 CPU matmuls #26's exactsegmented_mmtest and Apple's.Overlaps
None with the batch's other branches (merge-tree).
Validation
Compared with
main(23f364e), built and run the same way:tests/tests): 391 of 391 cases pass on the CPU and on Metal(
main390 of 390; the new case is [CPU] Fix strided half-precision GEMM dimensions in BNNS and simd_gemm ml-explore/mlx#4947's).main412 of 412).test_ops: GPU 174 pass;DEVICE=cpu172 pass, 2 skip; both asmain.test_cummax_cummin_nanas extended by Fix NaN propagation in CPU cummax and cummin for float16 and bfloat16 ml-explore/mlx#4912, run againstmain's build on the CPU, fails (float16cummaxof[1, 3, nan, 5, 4]); on this branch it passes.main(our Pass lda and ldb through to the bf16 and fp16 CPU matmuls #26 test already coversldaandldb;ldcis new).Validation of the batch in
sharedThis batch's PRs but the last (
fix/float-floor-divide, which came out of this validation), merged together onmain23f364e with the two overlap resolutions (apple/fixes-2andapple/r3-coreinpython/tests/test_quantized.py;apple/r3-coreandapple/fixes-3inmlx/allocator.h), are mlx 8de1a51; vmlx-swift 31458a0d3 builds on it (osaurus-ai/vmlx-swiftmainbbd237750 with our open vmlx-swiftpatches). Built and run, compared with
main:its suite (
swift test --no-parallel, 1046 tests) fails no test that passes on itsmain.main412 of 412).vmlx-swift's Linux CI steps pass:
VMLXLinuxTests37 of 37, the CPU kernel tests 61 of 61 at both thread settings.DEVICE=cpu,python/testsmodule by module, torch 2.15 for the CPU). arm64:main881 pass, 92 skip, 2 fail;the batch 906 pass, 96 skip, 2 fail (tree c43a37eec, which differs from 8de1a51 only in a C++ test). amd64:
main882 pass, 92 skip, 1 fail; the batch 906 pass, 96 skip, 1 fail, 1 error. No test that passes on
mainfails on the batch. The failures aremain's own:test_compile_sigmoid_matches_eager(bfloat16: the compiled CPU sigmoid is less accurate than theeager Highway kernel) and, on arm64 only, bfloat16
test_torch_conv_2D, where torch 2.15's own aarch64 bfloat16conv2d is off by up to 8.8 against float64 (MLX is within 0.06).
test_async_eval_error_in_synchronizefailed once on amd64; it fails about 1 run in 5 there onmaintoo: the error it expects fromsynchronizecan come fromasync_eval(the same code is on ml-explore/mlx main).mainfail at random, on every branch alike, because they draw unseeded inputs or race:test_double.TestDouble.test_unary_opsin about 8% of runs (float32erfis accurate to 1.5e-7 absolute, whichmisses
rtol1e-5 near 0 against the fork's accurate float64erf);test_ops.TestOps.test_divmodin about 1%(the float16 quotient is off by one when
a / brounds up to an integer, e.g. 73.625 / 1.248 = 58.99 gives 59;ml-explore/mlx main has the same code); and, on amd64,
test_async_eval_error_in_synchronize(above). This batch'sfix/float-floor-dividefixes the second; the first gets a PR of its own.its Linux and macOS jobs.
test_compile_sigmoid_matches_eager,test_torch_conv_2Das onmain.🤖 Generated with Claude Code